package leetcode.Leetcode11;

class DraftSolution {
    public int maxArea1(int[] height) {
        //两边选择一边更短的板向中间推，若新板比原板低或相等，那么可以直接跳过，因为面积一定减小
        //如果短边增大，则计算并更新最大面积
        int maxArea=Math.min(height[0],height[height.length-1])*(height.length-1);
        int i=0,j=height.length-1;

        while (i < j) {
            if (height[i] <= height[j]) {
                if (height[i + 1] > height[i]) {
                    i++;
                    maxArea = Math.max(maxArea, Math.min(height[i],height[j])*(j-i));
                    System.out.println(maxArea);
                } else {
                    i++;
                }
            } else {
                if (height[j - 1] > height[j]) {
                    j--;
                    maxArea = Math.max(maxArea, Math.min(height[i],height[j])*(j-i));
                    System.out.println(maxArea);
                } else {
                    j--;
                }
            }
        }
        return maxArea;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        int maxArea = solution.maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7});
        System.out.println("tets");
        System.out.println(maxArea);

    }
}